package gui;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.MenuItem;
import javafx.scene.control.Tab;
import javafx.scene.shape.Circle;
import javafx.stage.Popup;

public class TabContextMenu extends javafx.scene.control.ContextMenu
{
	private MenuItem save, save_as, rename, close;
	
	public TabContextMenu(Tab e)
	{
		super();
		
		save = new MenuItem("Save");
		save.setUserData(e);
		save.setOnAction(save_handler);
		
		save_as = new MenuItem("Save as...");
		save_as.setUserData(e);
		save_as.setOnAction(save_as_handler);
		
		rename = new MenuItem("Rename...");
		rename.setUserData(e);
		rename.setOnAction(rename_handler);
		
		close = new MenuItem("Close Image");
		close.setUserData(e);
		close.setOnAction(close_handler);
		
		this.getItems().addAll(save, save_as, rename, close);
	}
	
	private EventHandler<ActionEvent> save_handler = new EventHandler<ActionEvent>()
	{
		@Override public void handle(ActionEvent event)
		{
			MenuItem source = (MenuItem)event.getSource();
			Tab parent = (Tab)source.getUserData();
			System.out.println("Saving image: " + parent.getText());
			// TODO: save image - perhaps redirect to MenuBar -> File -> Save
		}
	};
	
	private EventHandler<ActionEvent> save_as_handler = new EventHandler<ActionEvent>()
	{
		@Override public void handle(ActionEvent event)
		{
			MenuItem source = (MenuItem)event.getSource();
			Tab parent = (Tab)source.getUserData();
			System.out.println("Saving image as: " + parent.getText());
			// TODO: save image as - perhaps redirect to MenuBar -> File -> Save As
		}
	};
	
	private EventHandler<ActionEvent> rename_handler = new EventHandler<ActionEvent>()
	{
		@Override public void handle(ActionEvent event)
		{
			MenuItem source = (MenuItem)event.getSource();
			Tab parent = (Tab)source.getUserData();
			
			// TODO: rename image
		}
	};
	
	private EventHandler<ActionEvent> close_handler = new EventHandler<ActionEvent>()
	{
		@Override public void handle(ActionEvent event)
		{
			MenuItem source = (MenuItem)event.getSource();
			Tab parent = (Tab)source.getUserData();
			System.out.println("Closing image: " + parent.getText());
			// TODO: check if image is not saved
			// TODO: close image
		}
	};
}
